package my.algorithms;

public class Factorial
{
    public static int recursiveFactorial(int n)
    {
        if (n == 0)
        {
            return 1;
        } 
        else
        {
            return n * recursiveFactorial(n - 1);
        }
    }
    
    public static int recursiveFactorialTail(int n, int total)
    {
        if (n == 1)
        {
            return 1 * total;
        } 
        else
        {
            return recursiveFactorialTail(n - 1 , total * n);
        }
    }

    public static int linearFactorial(int n)
    {
        int total = 1;
        for (int i = n; i > 0; i--)
        {
            total *= i;
        }
        return total;
    }
    
    public static void main(String []args)
    {
    	System.out.println(recursiveFactorialTail(5, 1));
    	System.out.println(linearFactorial(5));
    	System.out.println(recursiveFactorial(5));
    	
    }
}
